package com.lam.mall.service.impl;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.StringUtils;
import com.lam.mall.entity.PayInfo;
import com.lam.mall.mapper.PayInfoMapper;
import com.lam.mall.param.PayInfoParam;
import com.lam.mall.service.PayInfoService;

/**
 * 订单支付记录Service业务层处理
 * 
 * @author admin
 * @date 2023-05-07
 */
@Service
public class PayInfoServiceImpl  implements PayInfoService {

    @Autowired
    private PayInfoMapper payInfoMapper;

    /**
     * 查询订单支付记录
     * 
     * @param payId ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public PayInfo selectById(String payId) {

        return payInfoMapper.selectById(payId);
    }

    /**
     * 查询订单支付记录列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<PayInfo> selectList(PayInfoParam param) {
    
        QueryWrapper<PayInfo> queryWrapper = new QueryWrapper<>();
        
        queryWrapper.eq(StringUtils.isNotBlank(param.getPayId()), "pay_id", param.getPayId());
        queryWrapper.eq(Objects.nonNull(param.getUserId()), "user_id", param.getUserId());
        queryWrapper.eq(StringUtils.isNotBlank(param.getOrderIds()), "order_ids", param.getOrderIds());
        queryWrapper.eq(StringUtils.isNotBlank(param.getBizPayNo()), "biz_pay_no", param.getBizPayNo());
        queryWrapper.eq(Objects.nonNull(param.getPayType()), "pay_type", param.getPayType());
        queryWrapper.eq(Objects.nonNull(param.getPayStatus()), "pay_status", param.getPayStatus());
        queryWrapper.ge(Objects.nonNull(param.getCreateTimeBegin()), "create_time", param.getCreateTimeBegin());
        queryWrapper.le(Objects.nonNull(param.getCreateTimeEnd()), "create_time", param.getCreateTimeEnd());
        
        return payInfoMapper.selectList(queryWrapper);
    }

    /**
     * 新增订单支付记录
     * 
     * @param payInfo 
     * @return 
     */
    @Override
    @Transactional
    public int insert(PayInfo payInfo) {
    
        return payInfoMapper.insert(payInfo);
    }

    /**
     * 修改订单支付记录
     * 
     * @param payInfo 
     * @return 
     */
    @Override
    @Transactional
    public int update(PayInfo payInfo) {
    
        return payInfoMapper.updateById(payInfo);
    }

    /**
     * 删除订单支付记录信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    
        if(StringUtils.isBlank(idStr)) {
            return 0;
        }
        return payInfoMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }

}
